package org.example.bumenguanli.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.bumenguanli.pojo.*;
import org.example.bumenguanli.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
public class StudentController {
    @Autowired
    private StudentService studentService;

    @GetMapping("/students")
    public Result page(EmpQueryParam empQueryParam) {
        log.info("查询请求参数： {}", empQueryParam);
        PageResult pageResult = studentService.page(empQueryParam);
        return Result.success(pageResult);
    }

    @PostMapping("/students")
    public Result save(@RequestBody Student student) {
        log.info("新增请求参数： {}", student);
        studentService.save(student);
        return Result.success();
    }

    @GetMapping("/students/{id}")
    public Result getInfo(@PathVariable Integer id) {
        log.info("查询学生信息，id：{}", id);
        Student student = studentService.getInfo(id);
        return Result.success(student);
    }

    @PutMapping("/students")
    public Result update(@RequestBody Student student) {
        log.info("修改请求参数： {}", student);
        studentService.update(student);
        return Result.success();
    }

    @DeleteMapping("/students/{ids}")
    public Result delete(@PathVariable List<Integer> ids) {
        log.info("删除学生，id：{}", ids);
        studentService.delete(ids);
        return Result.success();
    }

    @PutMapping("/students/violation/{id}/{score}")
    public Result updateViolation(@PathVariable Integer id, @PathVariable Short score) {
        log.info("修改学生违规次数，id：{}，score：{}", id, score);
        studentService.updateViolation(id, score);
        return Result.success();
    }

    @GetMapping("/report/studentCountData")
    public Result studentCountData() {
        log.info("查询学生数量统计数据");
        ClazzOption clazzOption = studentService.studentCountData();
        return Result.success(clazzOption);
    }

    @GetMapping("/report/studentDegreeData")
    public Result studentDegreeData() {
        log.info("查询学生学历统计数据");
        List<Map> studentOption = studentService.studentDegreeData();
        return Result.success(studentOption);
    }
}
